<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::table('landing_companies', function (Blueprint $table) {
            if (! Schema::hasColumn('landing_companies', 'bank_name')) {
                $table->string('bank_name', 200)->after('email')->comment('开户行');
            }
            if (! Schema::hasColumn('landing_companies', 'account_number')) {
                $table->string('account_number', 100)->after('bank_name')->comment('银行账号');
            }
            if (! Schema::hasColumn('landing_companies', 'balance')) {
                $table->decimal('balance', 15, 2)->default(0)->after('account_number')->comment('账号余额');
            }
        });
    }

    public function down(): void
    {
        Schema::table('landing_companies', function (Blueprint $table) {
            if (Schema::hasColumn('landing_companies', 'balance')) {
                $table->dropColumn('balance');
            }
            if (Schema::hasColumn('landing_companies', 'account_number')) {
                $table->dropColumn('account_number');
            }
            if (Schema::hasColumn('landing_companies', 'bank_name')) {
                $table->dropColumn('bank_name');
            }
        });
    }
};
